<{extend name="public/layout"}>



<{block name="link"}>
<link rel="stylesheet" href="/static/adminlte/plugins/summernote/summernote-bs4.min.css">
<{/block}>
<{block name="content"}>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>订单详情</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="<{:url('/admin/index/index')}>">首页</a></li>
                        <li class="breadcrumb-item"><a href="<{:url('/admin/order.index/index')}>">订单管理</a></li>
                        <li class="breadcrumb-item active">订单详情</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <!-- Default box -->

    <section class="content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title"></h3>

                    <div class="card-tools">
                        <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                            <i class="fas fa-minus"></i>
                        </button>
                        <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                </div>
                <div class="card-body">
                    <table id="my_table" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>商品信息</th>
                            <th>订单信息</th>

                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>
                                <{foreach $data.goods_list as $k=> $goods}>
                                <div>
                                    <img src="<{$goods.thumb}>" style="max-width: 50px" alt="">

                                    <a href="<{:url('/mall/goods/detail')}>?id=<{$goods.goods_id}>" target="_blank">
                                        <{$goods.title}>
                                    </a>
                                    <p style="margin-top: 5px">
                                        <b>单价：</b><{$goods.price}>；
                                        <b>数量：</b><{$goods.count}>；
                                        <b>总价：</b><{:bcmul($goods.count,$goods.price,2)}>

                                    </p>
                                </div>
                                <{if !empty($data.goods_list[$k+1])}>
                                <hr class="cm-hr">
                                <{/if}>

                                <{/foreach}>
                            </td>
                            <td>
                                <p><b>单号：</b><{$data.order.order_sn}> </p>

                                <p><b>状态：</b>
                                    <{$data.order.statusDesc}>
                                    <{if $data.order.refund_total>0}>
                                    <span class="bs-red">（累计退款：<{$data.order.refund_total}>）</span>
                                    <{/if}>
                                </p>
                                <{if !empty($data.order.address)}>
                                <div onclick="copy(this)">
                                    <p><b>地址：</b><{$data.order.full_address}> </p>
                                    <p><b>收货人：</b><{$data.order.address.username}> </p>
                                    <p><b>收货号码：</b><{$data.order.address.mobile}> </p>
                                    <p><b>订单备注：</b><span style="color: red"><{$data.order.remark?$data.order.remark:'无'}></span> </p>
                                </div>
                                <{/if}>

                            </td>
                        </tr>


                        </tbody>

                    </table>

                    <div class="card">
                        <div class="card-body">
                            <p><b>订单类型：</b><{$data.order.order_type_desc}><b class="bs-left-20">订单状态：</b><{$data.order.statusDesc}></p>
                            <p><b>下单时间：</b><{$data.order.add_time|date="Y-m-d H:i:s",###}> <b class="bs-left-20">发货时间：</b><{$data.order.send_time}></p>
                            <p><b>收货时间：</b><{$data.order.receive_time}><b class="bs-left-20">付款时间：</b><{$data.order.pay_time}></p>
                        </div>
                    </div>
                    <{if !empty($data.order.refund)}>
                    <div class="card  ">
                        <div class="card-body ">
                            <div class="alert alert-warning alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h5><i class="icon fas fa-exclamation-triangle"></i> 注意!</h5>
                                订单有申请售后，请先处理售后。
                            </div>
                            <div class="card-body">
                                <strong><i class="fas fa-book mr-1"></i> 申请方式</strong>

                                <p class="text-muted">

                                    <{if($data.order.refund.apply_type==1)}>
                                    仅退款
                                    <{elseif $data.order.refund.apply_type==2}>
                                    退货退款
                                    <{else}>
                                    仅退货
                                    <{/if}>
                                </p>
                                <hr>

                                <strong><i class="fas fa-money-bill mr-1"></i> 申请金额</strong>

                                <p class="text-muted">
                                    ¥ <{$data.order.refund.apply_money}>
                                </p>

                                <hr>

                                <strong><i class="far fa-file-alt mr-1"></i> 申请原因</strong>

                                <p class="text-muted"><{$data.order.refund.apply_reason}></p>
                            </div>
                        </div>
                    </div>
                    <{/if}>


                </div>
                <div class="card-footer">
                    <b class="bs-left-30">应付：</b>￥<span class="bs-red "><{$data.order.price}>
                 <{if $data.order.status=='0'}>
                    <span  onclick="changePrice('<{$data.order.price}>')" class="btn btn-sm btn-warning bs-left-10">修改价格</span>
                    <{/if}>
                </span>
                    <b class="bs-left-30">实付：</b>￥<span class="bs-red "><{$data.order.pay_price}></span>
                    <b class="bs-left-30">优惠券抵扣：</b>￥<span class="bs-red "><{$data.order.coupon_money}>（原价<{$data.order.old_money}>）</span>
                    <{if $data.order.express_no}>
                    <p>
                        物流公司：<{$data.order.express_com}>；&nbsp;&nbsp; 物流单号：<{$data.order.express_no}>
                    </p>
                    <{/if}>
                    <p class="bs-top-30">

                        <{if !empty($data.order.refund)}>
                        <span class="btn  btn-warning bs-left-20" data-toggle="modal" data-target="#modal-refund">处理售后</span>
                        <{else}>

                        <{if $data.order.order_type==2}>
                        <{if $data.order.status==1}>
                        <!--提货专属-->
                        <span class="btn  btn-success tihuo-btn" >确认提货</span>
                        <{/if}>
                        <{else}>
                        <{if $data.order.order_type==3}>
                        <{if $data.order.status==1}>
                        <span class="btn  btn-success" data-toggle="modal" data-target="#modal-virtual">去发货</span>
                        <{elseif $data.order.status>=2}>
                        <span class="btn  btn-warning" data-toggle="modal" data-target="#modal-virtual">修改发货信息</span>
                        <{/if}>
                        <{else}>
                        <{if $data.order.status==1}>
                        <span class="btn  btn-success" data-toggle="modal" data-target="#modal-default">去发货</span>
                        <{elseif $data.order.status==2}>
                        <span class="btn  btn-warning" data-toggle="modal" data-target="#modal-default">修改物流</span>
                        <a class="btn btn-sm btn-primary" target="_blank" href="<{:url('/mall/order/express')}>?order_sn=<{$data.order.order_sn}>">查看物流</a>
                        <{/if}>
                        <{/if}>


                        <{/if}>



                        <{/if}>

                        <a href="<{:url('index')}>" class="btn btn-outline-primary bs-left-30" >返回列表</a>
                    </p>
                </div>
                <!-- /.card-body -->
            </div>
            <!-- /.card -->
        </div>

        <div class="bs-model">
            <{if !empty($data.order.refund)}>
            <div class="modal fade" id="modal-refund">
                <div class="modal-dialog">
                    <form action="<{:url('refund')}>" method="post" id="form-refund">
                        <input type="hidden" name="order_sn" value="<{$data.order.order_sn}>">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">售后维权处理</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">

                                    <label for="dotype">操作方式</label>
                                    <select name="dotype" id="dotype" class="form-control">
                                        <option value="1">同意退款</option>
                                        <option value="-1">驳回</option>
                                    </select>
                                </div>

                                <div class="form-group">

                                    <label for="refund_type">退款方式</label>
                                    <select name="refund_type" id="refund_type" class="form-control">
                                        <option value="1">原路退回</option>
                                        <option value="2">无需转账</option>
                                        <option value="3">手动转账</option>
                                    </select>
                                    <span class="bs-red">驳回时可以忽略。</span>
                                </div>
                                <div class="form-group">
                                    <label for="refuse_reason">驳回原因</label>
                                    <textarea name="refuse_reason" id="refuse_reason" class="form-control" placeholder="驳回请填写原因" cols="10" rows="3"></textarea>
                                    <span class="bs-red">驳回时必填。</span>
                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" onclick="refund()" class="btn btn-danger">提交处理</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <{/if}>

            <div class="modal fade" id="modal-default">
                <div class="modal-dialog">
                    <form action="<{:url('send')}>" method="post" id="check-form">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">订单发货</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label for="express_com">物流公司</label>
                                    <select name="express_com" id="express_com" class="form-control">
                                        <{foreach $data.expressCom as $v}>
                                        <option <{$data.order.express_com==$v.com?'selected':''}> value="<{$v.com}>"><{$v.name}></option>
                                        <{/foreach}>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="express_no">运单号</label>
                                    <input name="express_no" value="<{$data.order.express_no}>" type="text" class="form-control" id="express_no" placeholder="物流配送单号">
                                    <input type="hidden" name="order_sn" value="<{$data?$data.order.order_sn:''}>">
                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" onclick="send()" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <{if $data.order.order_type==3}>
            <div class="modal fade" id="modal-virtual">
                <div class="modal-dialog">
                    <form action="<{:url('send_virtual')}>" method="post" id="virtual">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">订单发货</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label for="content_virtual">发货内容</label>
                                    <textarea name="content_virtual" id="content_virtual"  class="form-control"><{$data.order.content_virtual}></textarea>
                                    <input type="hidden" name="order_sn" value="<{$data?$data.order.order_sn:''}>">
                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" onclick="send('virtual')" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <{/if}>


        </div>

    </section>
    <!-- /.content -->
</div>
<{/block}>
<{block name="script"}>
<script src="/static/adminlte/plugins/summernote/summernote-bs4.min.js"></script>
<script>
    var order_sn = '<{$data.order.order_sn}>';
    //上传图片
    function uploadFile($summernote, file) {
        var data = new FormData();
        data.append('fileKey','bs_shop')
        data.append('from','order')
        data.append("bs_shop", file);
        $.ajax({
            url:"<{:url('/admin/upload/image')}>",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (res) {
                res = JSON.parse(res)
                if (res.code==0){
                    console.log('xxx',res)
                    $summernote.summernote('insertImage', res.data.url, function ($image) {
                        $image.attr('src', res.data.url);
                    });
                    //$summernote.summernote('insertImage', res.data.url,'img');
                }

            }
        });
    }
    //删除图片
    function removeFile(target){
        var imgsrc = target[0].currentSrc;
        $.post('page/remove_img.php',{
            imgSrc:imgsrc
        },function(data){
            console.log(data);
        })

    }
    $(function () {
        $(".tihuo-btn").on('click',function () {
            layer.prompt({title: '请填写提货码', type: 1, value: ''}, function (value, index) {
                sendData("<{:url('action_tihuo')}>",{order_sn:order_sn,code:value},function (res) {
                    if (res.code==0){
                        layer.close(index);
                        location.reload();
                    }
                })

            })
        });

        var $summernote = $('#content_virtual').summernote({
            height:300,                 // set editor height
            minHeight:null,             // set minimum height of editor
            maxHeight:null,             // set maximum height of editor
            focus:true      ,            //
            callbacks: {
                //上传时调用
                onImageUpload: function (files) {
                    uploadFile($summernote, files[0]);
                },
                //删除时调用
                onMediaDelete: function (target) {
                    removeFile(target);
                }
            }

        });

    })

    function send(id){
        form_submit([],'',false,function(res) {
            if (res.code==0){
                location.reload();
            }
        },id)
    }

    function refund(){
        var dotype = $("select[name='dotype'] option:selected").val();
        var refund_type = $("select[name='refund_type'] option:selected").val();
        var refuse_reason = $("textarea[name='refuse_reason']").val();

        layer.confirm('确定提交处理申请售后吗？',{title:0},function () {

            if (dotype==-1 && !refuse_reason){
                return layer.alert('驳回请填写驳回原因',{title:0})
            }

            form_submit([],false,false,function (res) {
                if (res.code==0){
                    location.reload();
                }
            },'form-refund')

        })
    }

    $(function () {

        $("#my_table").DataTable({
            "searching": false,//禁用搜索
            "ordering": false,//禁用排序
            "responsive": true,
            "lengthChange": false,
            "autoWidth": false,
            //"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
            // "pageLength": 10,         //初始化显示几条数据
            //serverSide: true, // use local process instead of server
            // bFilter: true, // show top right search input box.
            bPaginate: false,//是否开启分页
            //iDisplayLength: 10, //默认显示的记录数
            bInfo: false,//是否显示页脚信息，DataTables插件左下角显示记录数
        }).buttons().container().appendTo('#my_table_wrapper .col-md-6:eq(0)');

    });

    function isAmount(value) {
        var regex = /^\d+(\.\d{1,2})?$/;
        return regex.test(value);
    }
    function changePrice(oldPrice){
        layer.prompt({title:'总金额调整',type:1,value:oldPrice},function (val,index) {
            if (oldPrice==val){
                return layer.msg('新的价格和原来的一样',{icon:5,time:1000})
            }
            if (!isAmount(val)){
                return layer.msg('金额格式不合法',{icon:5,time:1000})
            }
            sendData("<{:url('change_price')}>",{order_sn:order_sn,price:val},function (res) {
                if (res.code ==0){
                    return location.href = res.data.url
                }
            })
            layer.close(index)
            console.log(val)
        })
    }
</script>
<{/block}>
